﻿/*
Copyright (C) 2012 Laurent Tardif (laurent.tardif@persistentsas.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
*/
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using org.codeplex.TestUtils;
using System.IO;

namespace IQToolsFonctionalTests
{
    [TestClass]
    public class IQToolsTests
    {

        [TestMethod]
        public void TestBasicDiff_B06465_AT01472()
        {
            Console.WriteLine("start success");
            int errorCode = ShellUtils.ExecutePowershellScript("IQDiff.ps1", @"-file1 .\out1.xml -file2 .\out2.xml -output c:\temp\blabla.xml", 10000);
            Assert.AreEqual(0, errorCode, "The return code should be = 0 as all parameters are valid (directory)");
            Console.WriteLine("run success");
        }

        [TestMethod]
        public void TestBasicDiff_SimpleMode_B06465_AT01472()
        {
            Console.WriteLine("start success");
            int errorCode = ShellUtils.ExecutePowershellScript("IQDiff.ps1", @"-file1 .\out1.xml -file2 .\out2.xml -output c:\temp\blabla2.xml -simple", 10000);
            Assert.AreEqual(0, errorCode, "The return code should be = 0 as all parameters are valid (directory)");
            Console.WriteLine("run success");
        }

        [TestMethod]
        public void TestBasicDiff_FileDoNotExist_B06465_AT01472()
        {
            
            Console.WriteLine("start success");
            int errorCode = ShellUtils.ExecutePowershellScript("IQDiff.ps1", @"-file1 .\out1.xml -file2 .\out3.xml -output c:\temp\blabla3.xml -simple", 10000);
            Assert.AreEqual(0, errorCode, "The return code should be = 0 as all parameters are valid (directory)");
            Console.WriteLine("run success");
        }

        /// <summary>
        /// Test IQDiff on a hotfix without description
        /// </summary>
        [TestMethod]
        public void TestIQToolsFollowedByDiff_B06535_AT01568()
        {
            Console.WriteLine("start success");

            // Run IQTools
            String configurationFile = "config.xml";
            String generatedFile = "outIQTools.xml";
            Console.WriteLine("IQTools.ps1 -configFile " + configurationFile + " -outputFile " + generatedFile + " ");
            int errorCode = ShellUtils.ExecutePowershellScript("IQTools.ps1", @"-configFile " + configurationFile + " -outputFile " + generatedFile + " ", 50000);
            Assert.AreEqual(0, errorCode, "The return code for IQTools should be = 0 as all parameters are valid (directory)");

            // Run IQDiff using the same file
            Console.WriteLine("run success");
            String outIQDiffFile = @"c:\temp\blabla.xml";
            errorCode = ShellUtils.ExecutePowershellScript("IQDiff.ps1", @"-file1 " + generatedFile + " -file2 " + generatedFile + " -output " + outIQDiffFile, 10000);
            Assert.AreEqual(0, errorCode, "The return code for IQDiff should be = 0 as all parameters are valid (directory)");

            // Check there is no more difference
            Console.WriteLine("Will work with result file " + outIQDiffFile);
            Assert.IsTrue(File.Exists(outIQDiffFile), "the file " + outIQDiffFile + " should exist");
            String content = File.ReadAllText(outIQDiffFile);
            string sectionName = "additional_hotfix";
            Boolean check = StringUtils.CheckDoNotContains(content, "<" + sectionName);
            Assert.IsTrue(check, "File contains a " + sectionName + " section");

            Console.WriteLine("run success");
        }


    }
}
